package util;

public class Profiler {

	long start;
	long startMemory;
	long stop;
	long stopMemory;
	
	private static Profiler instance = null;
	
	
	public void start(){
		startMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
		System.out.println(Runtime.getRuntime().totalMemory()+ "|" +Runtime.getRuntime().freeMemory());
		start = System.currentTimeMillis();
	}
	
	public long stop(){
		stop = System.currentTimeMillis();
		System.out.println(Runtime.getRuntime().totalMemory()+ "|" +Runtime.getRuntime().freeMemory());
		stopMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
		return elapsedTime();
	}
	
	public long elapsedTime(){
		return stop - start;
	}
	
	public long elapsedHeap(){
		return stopMemory - startMemory;
	}
	
	public static Profiler getInstance(){
		if(instance == null){
			instance = new Profiler();
		}
		return instance;
	}
}
